// DB_op.cpp : implementation file
//

#include "stdafx.h"
#include "VolDia.h"
#include "DB_op.h"
#include "Twn_Pro_ph.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define INSR_STR	_T("DB Object Insert")
#define DECL_STR	_T("DB Object Declare")
#define REMO_STR	_T("DB Object Remove")

extern CVolDiaApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDB_op dialog


CDB_op::CDB_op(CWnd* pParent /*=NULL*/)
	: CDialog(CDB_op::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDB_op)
	m_Weight = 0.0f;
	//}}AFX_DATA_INIT
	this->m_dbOpExecuted = 0;
	this->m_defVx = 0;
	this->m_defVy = 0;
	this->m_defZoneIdx = -1;

}


void CDB_op::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDB_op)
	DDX_Control(pDX, IDC_OBJ, m_obj);
	DDX_Control(pDX, IDCANCEL, m_CancelCtrl);
	DDX_Control(pDX, IDC_INSERT, m_InsertCtrl);
	DDX_Control(pDX, IDC_LST_SITUATION, m_LstSituation);
	DDX_Control(pDX, IDC_CMB_ZONE, m_CmbZone);
	DDX_Control(pDX, IDC_CMB_OP_TYPE, m_CmbOpType);
	DDX_Control(pDX, IDC_CMB_OBJT, m_CmbObjt);
	DDX_Control(pDX, IDC_CMB_CELL, m_CmbCell);
	DDX_Text(pDX, IDC_OBJ_WEIGHT, m_Weight);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDB_op, CDialog)
	//{{AFX_MSG_MAP(CDB_op)
	ON_CBN_SELCHANGE(IDC_CMB_ZONE, OnSelchangeCmbZone)
	ON_CBN_SELCHANGE(IDC_CMB_OP_TYPE, OnSelchangeCmbOpType)
	ON_CBN_SELCHANGE(IDC_CMB_CELL, OnSelchangeCmbCell)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_WM_SHOWWINDOW()
	ON_CBN_SELCHANGE(IDC_CMB_OBJT, OnSelchangeCmbObjt)
	ON_BN_CLICKED(IDC_SET_WEIGHT, OnSetWeight)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDB_op message handlers

void CDB_op::OnCancel(){
	RETSTAT		retSt;
	int			opMode;

	retSt = GetDynCurrentMode(&opMode);
	if(retSt != RT_NORMAL){
		theApp.m_pDlg->m_pDB_op->CloseWindow();	
	}

	/*
	if((theApp.m_pDlg->m_pManual != NULL) && (opMode == M_PROTECT)){
		theApp.m_pDlg->m_pManual->ShowWindow(SW_SHOWNORMAL);
		theApp.m_pDlg->m_pDB_op->CloseWindow();	
	}

	if(theApp.m_pDlg->m_pTechCycle != NULL){
		theApp.m_pDlg->m_pTechCycle->ShowWindow(SW_SHOWNORMAL);
		theApp.m_pDlg->m_pDB_op->CloseWindow();	
	}
	if(theApp.m_pDlg->m_pPhaseExecDialog != NULL){
		theApp.m_pDlg->m_pPhaseExecDialog->ShowWindow(SW_SHOWNORMAL);
		theApp.m_pDlg->m_pPhaseExecDialog->ListUpdate(0);
		theApp.m_pDlg->m_pDB_op->CloseWindow();
	}
	*/
	CDialog::OnCancel();
}

BOOL CDB_op::OnInitDialog(){
	CDialog::OnInitDialog();
	
	return(this->InitDialog());  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDB_op::OnSelchangeCmbZone() 
{
	RETCOND		retCnd;
	RETSTAT		retSt;
	FILEIDX		fileCell;
	t_cell		cell;
	int			i;
	int			startRec;
	int			stopRec;
	GENIDX		contType;
	ZONENAME	zoneName;
	GENIDX		zoneIdx;
	GENIDX		zoneIOIdx;
	TCHAR		coord[20];
	int			insPos;

	retSt = GetZoneIdx(ZONE_IO, &zoneIOIdx);
	
	this->m_CmbZone.GetLBText(this->m_CmbZone.GetCurSel(), zoneName);
	retSt = GetZoneIdx(zoneName, &zoneIdx);
	if(retSt != RT_NORMAL)
		MessageBox(_T("Error retrieving zone Idx."), _T("Error"), MB_OK|MB_ICONERROR);

	fileCell.num = F_CE01 + zoneIdx - 1;
	
	if(zoneIdx == zoneIOIdx){
		retSt = GetDynCurrentCont(&contType);
		switch(contType){
		case Z1_NO_CONT:
			MessageBox(_T("No container in zone 1, select a container to execute database operations in this zone."), _T("Warning"), MB_OK | MB_ICONINFORMATION);
			goto END;
			break;
		case Z1_CONT_TK13:
			startRec = 1;
			stopRec = CONT_TK13_CELLS;
			break;
		case Z1_CONT_LOAD:
			startRec = CONT_TK13_CELLS + 1;
			stopRec = CONT_TK13_CELLS + CONT_LOAD_CELLS;
			break;
		case Z1_CONT_HECA:
			startRec = CONT_TK13_CELLS + CONT_LOAD_CELLS + 1;
			stopRec = CONT_TK13_CELLS + CONT_LOAD_CELLS + CONT_HECA_CELLS;
			break;
		default:
			MessageBox(_T("No container in zone 1, select a container to execute database operations in this zone."), _T("Warning"), MB_OK | MB_ICONINFORMATION);
			goto END;
			break;
		}
	}
	else{
		startRec = 1;
		stopRec = N_MAX_CELL;
	}

	this->m_CmbCell.ResetContent();
	for(i = startRec; i <= stopRec; i++){
		retCnd = FileRead(&fileCell, i, 1, &cell, sizeof(cell));
		if(retCnd != R_NORMAL)
			MessageBox(_T("Error reading DAFS file F_CEnn."), _T("Error"), MB_OK|MB_ICONERROR);
		if((cell.Virt_X != 0) && (cell.Virt_Y != 0) && ((cell.Virt_X % 100) != 0)){
			_stprintf_s(coord, _T("(%d,%d)"), cell.Virt_X, cell.Virt_Y);
			insPos = this->m_CmbCell.AddString(coord);
			this->m_CmbCell.SetItemData(insPos, i);
		}
		else if((cell.Virt_X == 0) && (cell.Virt_Y == 0))
			break;
	}

	this->m_CmbCell.SetCurSel(0);
	OnSelchangeCmbCell();	
END:
	UpdateData(false);
}

void CDB_op::OnSelchangeCmbOpType(){
	RETSTAT		retSt;
	OBJTCELL	cellSit;
	int			i;
	TCHAR		op[30];
	
	this->m_CmbOpType.GetLBText(this->m_CmbOpType.GetCurSel(), op);	
	if(!_tcscmp(op, INSR_STR)){
		this->m_CmbObjt.SetCurSel(0);
		this->m_obj.SetWindowText(_T(""));
		this->m_Weight = 0.0;
	}
	else{
		retSt = GetCellSituation(this->m_defVx, this->m_defVy, &cellSit);
		if(retSt == R_NORMAL){
			for(i = 0; i < N_MAX_NONAM_OBJ; i++){
				if(cellSit.obj[i] != 0){
					this->m_CmbObjt.SetCurSel(cellSit.obj[i] - 1);
					break;
				}
			}
		}
	}
	UpdateData(false);
}



void CDB_op::OnSelchangeCmbCell(){
	RETSTAT		retSt;
	OBJTNAME	objtName;
	OBJNAME		objName;
	int			i;
	int			vx, vy;
	int			numObj;
	TCHAR		coord[20];
	TCHAR		temp[100];
	
	numObj = 0;

	this->m_LstSituation.ResetContent();
	this->m_CmbCell.GetLBText(this->m_CmbCell.GetCurSel(), coord);	
	_stscanf_s(coord, _T("(%d,%d)"), &vx, &vy);
	
	retSt = GetCellSituation(vx, vy, &this->m_cellSituation);
	if(retSt != RT_NORMAL)
		MessageBox(_T("Error retrieving cell information."), _T("Error"), MB_OK|MB_ICONERROR);
	else{
		_stprintf_s(temp, _T("Objects in cell %s:"), coord);
		this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), temp);
		this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), _T("-------------------------------------------------------------------------------------------------------"));
		for(i = 0; i < N_MAX_NONAM_OBJ; i++){
			if(this->m_cellSituation.obj[i] != 0){
				numObj++;
				_stprintf_s(temp, _T("Object %d:"), numObj);
				this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), temp);
				GetObjtName(this->m_cellSituation.obj[i], objtName);
				_stprintf_s(temp, _T("Object type: %s"), objtName);
				this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), temp);
				if(i < N_MAX_NAMED_OBJ){
					if(this->m_cellSituation.o_id[i] != 0){
						GetObjName(this->m_cellSituation.o_id[i], objName);
						_stprintf_s(temp, _T("Object name: %s"), objName);
						this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), temp);
					}
				}
				this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), _T(""));
			}
		}
		if(!numObj)
			this->m_LstSituation.InsertString(this->m_LstSituation.GetCount(), _T("No objects in cell."));
		else{
			//Aggiorno il combo con gli oggetti.//
			for(i = 0; i < N_MAX_NONAM_OBJ; i++){
				if(this->m_cellSituation.obj[i] != 0){
					//GetObjtGenericTypeCode(this->m_cellSituation.obj[i], &genType);
					this->m_CmbObjt.SetCurSel(this->m_cellSituation.obj[i] - 1);
				}
			}
		}
	}
	UpdateData(false);
}

void CDB_op::OnInsert() 
{
	RETCOND		retCnd;
	RETSTAT		retSt;
	PHASTAT		retPh;
	FILEIDX		filePhas;
	phas_struc	phas;
	GENIDX		Idx;
	TCHAR		temp[50];
	TCHAR		coord[20];
	int			vx, vy;
	OBJNAME		objName;
	OBJTNAME	objtName;
	int			currPhas;
	float		weight;
	float		objtWeight;
	int			risp;
	int			objtGenCode;
	bool		opOK;
	
	ZeroMemory(&phas, sizeof(phas_struc));
	filePhas.num = F_PHAS;
	retSt = GetDynCurrentPhase(&currPhas);
	opOK = false;

	UpdateData(true);

	this->m_CmbCell.GetLBText(this->m_CmbCell.GetCurSel(), coord);	
	_stscanf_s(coord, _T("(%d,%d)"), &vx, &vy);
	//this->m_CmbObj.GetLBText(this->m_CmbObj.GetCurSel(), objName);	
	this->m_obj.GetWindowText(objName, L_OBJ_NAME + 1);
	this->m_CmbObjt.GetLBText(this->m_CmbObjt.GetCurSel(), temp);
	this->m_CmbOpType.GetLBText(this->m_CmbOpType.GetCurSel(), coord);
	weight = this->m_Weight;
	
	if(!_tcscmp(coord, INSR_STR))
		_stprintf_s(phas.cmd_type, _T("%s"), MAC_INSR);
	else if(!_tcscmp(coord, DECL_STR))
		_stprintf_s(phas.cmd_type, _T("%s"), MAC_DECL);
	else if(!_tcscmp(coord, REMO_STR))
		_stprintf_s(phas.cmd_type, _T("%s"), MAC_REMO);
	else{
		MessageBox(_T("Unknown operation."), _T("Error"), MB_OK|MB_ICONERROR);
		goto END;
	}
	
	phas.phase = N_MAX_PHASE;
	phas.SV_X = vx;
	phas.SV_Y = vy;
	phas.DV_X = 0;
	phas.DV_Y = 0;
	GetObjtIdxFromDescription(temp, &Idx);
	GetObjtName(Idx, objtName);
	_stprintf_s(phas.obj_type, _T("%s"), objtName);
	_stprintf_s(phas.object, _T("%s"), objName);
	phas.esito = PHAS_TOEXECUTE;
	retCnd = FileWrite(&filePhas, N_MAX_PHASE, 1, &phas, sizeof(phas));
	if(retCnd != R_NORMAL){
		MessageBox(_T("Error writing DAFS file F_PHAS."), _T("Error"), MB_OK|MB_ICONERROR);
		goto END;
	}
	retSt = SetPhaseStartFlag(phas.phase, true);
	retSt = SetDynCurrentPhase(N_MAX_PHASE);
	retSt = GetObjtGenericTypeCode(Idx, &objtGenCode);
	if(!_tcscmp(coord, INSR_STR)){
		if(weight == 0){
			retSt = GetObjtWeight(Idx, &objtWeight);
			_stprintf_s(temp, _T("Object weight = 0, set weight to defualt object type weight = %.1f Kg?"), objtWeight);
			risp = MessageBox(temp, _T("Warning"), MB_YESNO | MB_ICONINFORMATION);
			if(risp == IDYES)
				weight = objtWeight;
			else{
				MessageBox(_T("Insert operation aborted, missing object weight"), _T("Error"), MB_OK | MB_ICONERROR);
				goto END;
			}
		}
		retPh = Pro_Ph_Insr();
		if(retPh != PH_NORMAL){
			if(retPh == PH_OBJEXIST)
				_stprintf_s(temp, _T("Cannot insert object %s in cell (%d,%d) failed.\nObject already present in system."), phas.object, phas.SV_X, phas.SV_Y);
			else
				_stprintf_s(temp, _T("DB INSERT of object %s in cell (%d,%d) failed."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Error"), MB_OK|MB_ICONERROR);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			goto END;
		}
		if(objtGenCode < N_MAX_NAMED_OBJ){
			retSt = GetObjIdx(phas.object, &Idx);
			if(retSt != RT_NORMAL){
				_stprintf_s(temp, _T("Error setting object %s weight."), phas.object);
				MessageBox(temp, _T("Error"), MB_OK|MB_ICONERROR);
				if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
					theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
				goto END;
			}
			retSt = SetObjWeight(Idx, weight);
			if(retSt != RT_NORMAL){
				_stprintf_s(temp, _T("Error setting object %s weight."), phas.object);
				MessageBox(temp, _T("Error"), MB_OK|MB_ICONERROR);
				if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
					theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
				goto END;
			}
			else{
				_stprintf_s(temp, _T("Object %s sucessfully inserted in cell (%d,%d)."), phas.object, phas.SV_X, phas.SV_Y);
				MessageBox(temp, _T("Success"), MB_OK|MB_ICONINFORMATION);
				if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
					theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
				opOK = true;
				goto END;
			}
		}
		else{
			_stprintf_s(temp, _T("Object %s sucessfully inserted in cell (%d,%d)."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Success"), MB_OK|MB_ICONINFORMATION);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			this->OnSelchangeCmbCell();
			opOK = true;
			goto END;
		}
	}
	else if(!_tcscmp(coord, DECL_STR)){
		retPh = Pro_Ph_Decl();
		if(retPh != PH_NORMAL){
			_stprintf_s(temp, _T("DB DECLARE of object %s in cell (%d,%d) failed."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Error"), MB_OK|MB_ICONERROR);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			goto END;
		}
		else{
			_stprintf_s(temp, _T("Type of object %s in cell (%d,%d) sucessfully declared."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Error"), MB_OK|MB_ICONINFORMATION);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			this->OnSelchangeCmbCell();
			opOK = true;
			goto END;
		}
	}
	else if(!_tcscmp(coord, REMO_STR)){
		retPh = Pro_Ph_Remo();
		if(retPh != PH_NORMAL){
			_stprintf_s(temp, _T("DB REMOVE of object %s from cell (%d,%d) failed."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Error"), MB_OK|MB_ICONERROR);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			goto END;
		}
		else{
			_stprintf_s(temp, _T("Object %s sucessfully removed from cell (%d,%d)."), phas.object, phas.SV_X, phas.SV_Y);
			MessageBox(temp, _T("Error"), MB_OK|MB_ICONINFORMATION);
			if(theApp.m_pDlg->m_pPhaseExecDialog != NULL)
				theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(temp);
			this->OnSelchangeCmbCell();
			opOK = true;
			goto END;
		}
	}
END:
	retSt = SetDynCurrentPhase(currPhas);
	if(opOK && (theApp.m_pDlg->m_pPosInfoDialog != NULL))
		theApp.m_pDlg->m_pPosInfoDialog->SetInputCoord(vx, vy);
	if(opOK && (theApp.m_pDlg->m_pManual != NULL)){
		theApp.m_pDlg->m_pManual->LoadMast();
		theApp.m_pDlg->m_pManual->LoadCell();
	}
	if(opOK){
		SetDynSPRefresh(1);
	}
}

BOOL CDB_op::InitDialog(void){
	RETCOND		retCnd;
	FILEIDX		fileZone;
	t_zone		zone;
	FILEIDX		fileObjt;
	t_obj_type	objt;
	FILEIDX		fileObje;
	int			i;
	int			pos;

	fileZone.num = F_ZONE;
	fileObjt.num = F_OBJT;
	fileObje.num = F_OBJE;

	this->m_CmbZone.ResetContent();
	this->m_CmbOpType.ResetContent();
	this->m_CmbObjt.ResetContent();

	ZeroMemory(&this->m_cellSituation, sizeof(OBJTCELL));

	//Aggiungo le tre operazioni al combo...//
	this->m_CmbOpType.InsertString(0, INSR_STR);
	this->m_CmbOpType.InsertString(1, REMO_STR);
	this->m_CmbOpType.InsertString(2, DECL_STR);
	this->m_CmbOpType.SetCurSel(0);

	//Limito le lunghezze del testo iseribile.//
	this->m_obj.LimitText(L_OBJ_NAME + 1);

	//Riempo il combo delle zone.//
	for(i = 1; i <= N_MAX_ZONE; i++){
		retCnd = FileRead(&fileZone, i, 1, &zone, sizeof(t_zone));
		if(retCnd != RT_NORMAL)
			MessageBox(_T("Error reading DAFS file F.ZONE."), _T("Error"), MB_OK|MB_ICONERROR);
		else{
			if(_tcscmp(zone.name, _T("")) && (zone.virtualZone == 0))
				this->m_CmbZone.InsertString(i - 1, zone.name);
		}
	}
	this->m_CmbZone.SetCurSel(1);
	OnSelchangeCmbZone(); 

	//Riempo il combo dei tipi di oggetti.//
	for(i = 1; i <= N_MAX_OBJT; i++){
		retCnd = FileRead(&fileObjt, i, 1, &objt, sizeof(objt));
		if(retCnd != RT_NORMAL)
			MessageBox(_T("Error reading DAFS file F.OBJT."), _T("Error"), MB_OK|MB_ICONERROR);
		else{
			if(objt.idx != 0){
				pos = this->m_CmbObjt.InsertString(objt.idx - 1, objt.obj_descr);
				this->m_CmbObjt.SetItemData(pos, objt.idx);
			}
			else
				break;
		}
	}

	//this->m_CmbObjt.SetCurSel(0);
	
	OnSelchangeCmbObjt();
	
	UpdateData(false);

	return(TRUE);
}

void CDB_op::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	this->UpdateVal(); 	
}

BOOL CDB_op::UpdateVal(void){
	RETCOND		retCnd;
	FILEIDX		fileCell;
	t_cell		cell;
	int			i;
	int			j;

	this->m_CmbZone.SetCurSel(this->m_defZoneIdx - 1);

	OnSelchangeCmbZone(); 

	fileCell.num = F_CE01 + this->m_defZoneIdx - 1;

	for(i = 1; i <= N_MAX_CELL; i++){
		retCnd = FileRead(&fileCell, i, 1, &cell, sizeof(cell));
		if(retCnd != R_NORMAL)
			MessageBox(_T("Error reading DAFS file F_CEnn."), _T("Error"), MB_OK|MB_ICONERROR);
		if((cell.Virt_X == this->m_defVx) && (cell.Virt_Y == this->m_defVy)){
			for(j = 0; j < this->m_CmbCell.GetCount(); j++){
				if((int)(this->m_CmbCell.GetItemData(j)) == i){
					this->m_CmbCell.SetCurSel(j);
					break;
				}
			}	
		}
	}
	
	OnSelchangeCmbCell();	
	OnSelchangeCmbObjt();
	UpdateData(false);

	return(TRUE);
}

void CDB_op::OnSelchangeCmbObjt(){
	RETSTAT		retSt;
	GENIDX		objtIdx;
	OBJNAME		ObjectName;
	int			genType;

	objtIdx = this->m_CmbObjt.GetCurSel() + 1;
	GetObjtGenericTypeCode(objtIdx, &genType);

	if(genType < N_MAX_NAMED_OBJ){
		this->m_obj.EnableWindow(true);
		if((this->m_cellSituation.o_id[genType] != 0) && (this->m_cellSituation.obj[genType] != 0)){
			retSt = GetObjName(this->m_cellSituation.o_id[genType], ObjectName);
			if(retSt == RT_NORMAL)
				this->m_obj.SetWindowText(ObjectName);
			else
				this->m_obj.SetWindowText(_T(""));
			GetObjWeight(this->m_cellSituation.o_id[genType], &this->m_Weight);
		}
		else{
			this->m_obj.SetWindowText(_T(""));
			this->m_Weight = 0.0;
		}
	}
	else{
		this->m_obj.EnableWindow(false);
		this->m_obj.SetWindowText(_T(""));
		GetObjtWeight(objtIdx, &this->m_Weight);
	}

	this->UpdateData(false);
}

void CDB_op::OnSetWeight(){
	RETSTAT		retSt;
	GENIDX		objtIdx;
	int			genType;

	this->UpdateData(true);
	
	objtIdx = (GENIDX)(this->m_CmbObjt.GetItemData(this->m_CmbObjt.GetCurSel()));
	GetObjtGenericTypeCode(objtIdx, &genType);

	if(genType < N_MAX_NAMED_OBJ){
		if(this->m_cellSituation.o_id[genType] == 0)
			return;
		else{
			retSt = SetObjWeight(this->m_cellSituation.o_id[genType], this->m_Weight);
			if(retSt != RT_NORMAL){
				MessageBox(_T("Error setting object weight"), _T("Error"), MB_OK | MB_ICONERROR);
				return;
			}
			else{
				if(theApp.m_pDlg->m_pPosInfoDialog != NULL)
					theApp.m_pDlg->m_pPosInfoDialog->SetInputCoord(-1, -1);
				MessageBox(_T("Object weight set."), _T("Success"), MB_OK | MB_ICONINFORMATION);
				return;
			}
		}
	}
	else{
		if(this->m_cellSituation.obj[genType] == 0)
			return;
		else{
			retSt = SetObjtWeight(this->m_cellSituation.obj[genType], this->m_Weight);
			if(retSt != RT_NORMAL){
				MessageBox(_T("Error setting object type weight"), _T("Error"), MB_OK | MB_ICONERROR);
				return;
			}
			else{
				if(theApp.m_pDlg->m_pPosInfoDialog != NULL)
					theApp.m_pDlg->m_pPosInfoDialog->SetInputCoord(-1, -1);
				MessageBox(_T("Object type weight set."), _T("Success"), MB_OK | MB_ICONINFORMATION);
				return;
			}
		}
	}

}
